<?php
class Tag extends CI_Controller {
	
	private $user_id;
	
	public function __construct()
	{
		parent::__construct();
		$this->user_utils->filter_login();
		$this->user_id = $this->user_utils->get_session_attribute(Variable::SESSION_USER_ID);
		
		$this->load->model('tag_model');
		$this->load->library('service/tag_service');
	}
	
	public function detail($tag_id = 0)
	{
		$tag = $this->tag_model->get_tag_by_id($tag_id);
		
		$data = array('view'=>'tag/detail', 'tag'=>$tag);
		$this->load->view('member/index', $data);
	}
	
	public function add()
	{
		$tag_name = $this->input->get_post('tagName');
		$this->tag_model->add_tag($this->user_id, $tag_name);
		
		$data['result'] = 'true';
		$this->load->view('tag/result', $data);
	}
	
	public function update()
	{
		$tag_id = $this->input->post('tagId');
	
		$tag_name = $this->input->post('tagName');
		$this->tag_service->update_tag($this->user_id, $tag_id, $tag_name);

		$data['result'] = 'true';
		$this->load->view('tag/result', $data);
	}
	
	public function del()
	{
		$tag_id = $this->input->get_post('tagId');
		$this->tag_service->del_tag($this->user_id, $tag_id);
		
		$data['result'] = 'true';
		$this->load->view('tag/result', $data);
	}
}
?>